home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 409_01 / test16.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-22  |  9.5 KB  |  296 lines

  1. /****************************************************************************
  2. *
  3. *                          SuperVGA Test Library
  4. *
  5. *                   Copyright (C) 1993 SciTech Software
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $RCSfile: test16.c $
  9. * Version:      $Revision: 1.2 $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  IBM PC (MSDOS)
  13. *
  14. * Description:  Simple program to test the operation of the SuperVGA
  15. *               test kit library's bank switching and page flipping code
  16. *               for 16 color SuperVGA video modes.
  17. *
  18. *               MUST be compiled in the large model.
  19. *
  20. * $Id: test16.c 1.2 1993/10/22 08:58:40 kjb release $
  21. *
  22. ****************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <dos.h>
  28. #include <conio.h>
  29. #include "svga.h"
  30.  
  31. /*---------------------------- Global Variables ---------------------------*/
  32.  
  33. #include "version.c"
  34.  
  35. int     x,y;
  36.  
  37. /* External routines */
  38.  
  39. void _copyTest16(void);
  40.  
  41. /*----------------------------- Implementation ----------------------------*/
  42.  
  43. void moireTest(void)
  44. /****************************************************************************
  45. *
  46. * Function:     moireTest
  47. *
  48. * Description:  Draws a simple Moire pattern on the display screen using
  49. *               lines, and waits for a key press.
  50. *
  51. ****************************************************************************/
  52. {
  53.     uchar   buf[80];
  54.     int     i;
  55.  
  56.     clear();
  57.     for (i = 0; i < maxx; i += 10) {
  58.         line(maxx/2,maxy/2,i,0,i % maxcolor);
  59.         line(maxx/2,maxy/2,i,maxy,(i+1) % maxcolor);
  60.         }
  61.     for (i = 0; i < maxy; i += 10) {
  62.         line(maxx/2,maxy/2,0,i,(i+2) % maxcolor);
  63.         line(maxx/2,maxy/2,maxx,i,(i+3) % maxcolor);
  64.         }
  65.     line(0,0,maxx,0,defcolor);
  66.     line(0,0,0,maxy,defcolor);
  67.     line(maxx,0,maxx,maxy,defcolor);
  68.     line(0,maxy,maxx,maxy,defcolor);
  69.  
  70.     if (maxx != 319) {
  71.         x = 80;
  72.         y = 80;
  73.         writeText(x,y,"Bank switching test",defcolor);  y += 32;
  74.         sprintf(buf,"Video mode: %d x %d 16 color",maxx+1,maxy+1);
  75.         writeText(x,y,buf,defcolor);    y += 16;
  76.         sprintf(buf,"Maximum x: %d, Maximum y: %d, BytesPerLine %d, Pages: %d",
  77.             maxx,maxy,bytesperline,maxpage+1);
  78.         writeText(x,y,buf,defcolor);    y += 32;
  79.         writeText(x,y,"You should see a colorful Moire pattern on the screen",defcolor);
  80.         y += 16;
  81.         }
  82.     else {
  83.         x = 40;
  84.         y = 40;
  85.         }
  86.     writeText(x,y,"Press any key to continue",defcolor);
  87.     y += 32;
  88.     getch();
  89. }
  90.  
  91. void readWriteTest(void)
  92. /****************************************************************************
  93. *
  94. * Function:     readWriteTest
  95. *
  96. * Description:  Test the separate read/write bank routines if available.
  97. *               We do this by copying the top half of video memory to
  98. *               the bottom half of the second video page.
  99. *
  100. *               This test is designed to run only in the 800x600 video mode.
  101. *
  102. ****************************************************************************/
  103. {
  104.     if (twobanks && maxpage != 0 && (maxx == 799)) {
  105.         writeText(x,y,"To test the separate read/write banks, the top half of",defcolor);
  106.         y += 16;
  107.         writeText(x,y,"this display page should be moved to the bottom half of",defcolor);
  108.         y += 16;
  109.         writeText(x,y,"the second display page",defcolor);
  110.         setActivePage(1);
  111.         clear();
  112.         setVisualPage(1);
  113.         _copyTest16();
  114.         x = y = 80;
  115.         writeText(x,y,"Press any key to continue",defcolor);
  116.         getch();
  117.         }
  118. }
  119.  
  120. void pageFlipTest(void)
  121. /****************************************************************************
  122. *
  123. * Function:     pageFlipTest
  124. *
  125. * Description:  Animates a line on the display using page flipping if
  126. *               page flipping is active.
  127. *
  128. ****************************************************************************/
  129. {
  130.     int     i,j,istep,jstep,color,apage,vpage;
  131.     char    buf[80];
  132.  
  133.     if (maxpage != 0) {
  134.         vpage = 0;
  135.         apage = 1;
  136.         setActivePage(apage);
  137.         setVisualPage(vpage);
  138.         i = 0;
  139.         j = maxy;
  140.         istep = 2;
  141.         jstep = -2;
  142.         color = 15;
  143.         while (!kbhit()) {
  144.             setActivePage(apage);
  145.             clear();
  146.             sprintf(buf,"Page %d of %d", vpage+1, maxpage+1);
  147.             if (maxx == 319) {
  148.                 writeText(0,80,"Page flipping - should be no flicker",defcolor);
  149.                 writeText(0,100,buf,defcolor);
  150.                 }
  151.             else {
  152.                 writeText(80,80,"Page flipping - should be no flicker",defcolor);
  153.                 writeText(80,100,buf,defcolor);
  154.                 }
  155.             line(i,0,maxx-i,maxy,color);
  156.             line(0,maxy-j,maxx,j,color);
  157.             vpage = ++vpage % (maxpage+1);
  158.             setVisualPage(vpage);
  159.             apage = ++apage % (maxpage+1);
  160.             i += istep;
  161.             if (i > maxx) {
  162.                 i = maxx-2;
  163.                 istep = -2;
  164.                 }
  165.             if (i < 0)  i = istep = 2;
  166.             j += jstep;
  167.             if (j > maxy) {
  168.                 j = maxy-2;
  169.                 jstep = -2;
  170.                 }
  171.             if (j < 0)  j = jstep = 2;
  172.             }
  173.         getch();                /* Swallow keypress */
  174.         }
  175. }
  176.  
  177. void testingComplete(void)
  178. /****************************************************************************
  179. *
  180. * Function:     testingComplete
  181. *
  182. * Description:  Clears the first display page and puts up a message.
  183. *
  184. ****************************************************************************/
  185. {
  186.     setActivePage(0);
  187.     setVisualPage(0);
  188.     clear();
  189.  
  190.     if (maxx == 319) {
  191.         writeText(0,40,"Testing complete",defcolor);
  192.         writeText(0,60,"press any key to return to text mode",defcolor);
  193.         }
  194.     else
  195.         writeText(80,80,"Testing complete - press any key to return to text mode",defcolor);
  196.     getch();
  197. }
  198.  
  199. int queryCpu(void);
  200.  
  201. void main(void)
  202. {
  203.     int     i,choice,maxmenu;
  204.     int     xres,yres,bitsperpixel,memmodel,maxpage;
  205.     long    pagesize;
  206.     int     menu[20];
  207.     char    buf[80];
  208.  
  209.     if (queryCpu() < 4) {
  210.         printf("This program contains '386 specific instructions, and will not work on\n");
  211.         printf("this machine - sorry\n");
  212.         }
  213.  
  214.     if (initSuperVGA() != 0x102) {
  215.         printf("This program requires a VESA VBE 1.2 compatible SuperVGA. Try installing\n");
  216.         printf("the Universal VESA VBE for your video card, or contact your video card\n");
  217.         printf("vendor and ask for a suitable TSR\n");
  218.         exit(1);
  219.         }
  220.  
  221.     while (true) {
  222. #ifdef  __TURBOC__
  223.         clrscr();
  224. #endif
  225.         printf("16 color SuperVGA test program (Version %s)\n\n",version);
  226.         printf("VBE OEM string: %s\n",OEMString);
  227.         printf("Memory:         %dk\n",memory);
  228.         printf("\n");
  229.         printf("Separate read/write banks: %s\n", twobanks ? "Yes" : "No");
  230.         printf("Extended page flipping:    %s\n", extendedflipping ? "Yes" : "No");
  231.         printf("8 bit wide DAC support:    %s\n", widedac ? "Yes" : "No");
  232.         printf("\n");
  233.         printf("Which video mode to test:\n\n");
  234.  
  235.         maxmenu = 0;
  236.  
  237.         /* Add standard VGA modes to menu */
  238.  
  239.         getSuperVGAModeInfo(menu[maxmenu] = 0x0D,&xres,&yres,&bytesperline,
  240.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  241.         printf("    [%2d] - %d x %d 16 color (%d page)\n",maxmenu++,
  242.             xres,yres,maxpage+1);
  243.  
  244.         getSuperVGAModeInfo(menu[maxmenu] = 0x0E,&xres,&yres,&bytesperline,
  245.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  246.         printf("    [%2d] - %d x %d 16 color (%d page)\n",maxmenu++,
  247.             xres,yres,maxpage+1);
  248.  
  249.         getSuperVGAModeInfo(menu[maxmenu] = 0x10,&xres,&yres,&bytesperline,
  250.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  251.         printf("    [%2d] - %d x %d 16 color (%d page)\n",maxmenu++,
  252.             xres,yres,maxpage+1);
  253.  
  254.         getSuperVGAModeInfo(menu[maxmenu] = 0x12,&xres,&yres,&bytesperline,
  255.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  256.         printf("    [%2d] - %d x %d 16 color (%d page)\n",maxmenu++,
  257.             xres,yres,maxpage+1);
  258.  
  259.         for (i = 0; modeList[i] != -1; i++) {
  260.             /* Filter out the 16 color planar video modes */
  261.  
  262.             if (!getSuperVGAModeInfo(modeList[i],&xres,&yres,&bytesperline,
  263.                     &bitsperpixel,&memmodel,&maxpage,&pagesize))
  264.                 continue;
  265.             if ((bitsperpixel == 4) && (memmodel == memPL)) {
  266.                 printf("    [%2d] - %d x %d 16 color (%d page)\n",maxmenu,
  267.                     xres,yres,maxpage+1);
  268.                 menu[maxmenu++] = modeList[i];
  269.                 }
  270.             }
  271.         printf("    [ Q] - Quit\n\n");
  272.         printf("Choice: ");
  273.  
  274.         gets(buf);
  275.         if (buf[0] == 'q' || buf[0] == 'Q')
  276.             break;
  277.  
  278.         choice = atoi(buf);
  279.         if (0 <= choice && choice < maxmenu) {
  280.             if (!setSuperVGAMode(menu[choice])) {
  281.                 printf("\n");
  282.                 printf("ERROR: Video mode did not set correctly!\n\n");
  283.                 printf("\nPress any key to continue...\n");
  284.                 getch();
  285.                 }
  286.             else {
  287.                 moireTest();
  288.                 readWriteTest();
  289.                 pageFlipTest();
  290.                 testingComplete();
  291.                 restoreMode();
  292.                 }
  293.             }
  294.         }
  295. }
  296.